package progress.exa28_1.part5;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程同步编程测试类
 */
public class ThreadSynStudy {

    public static void main(String[] args) {

        ExecutorService executorService = Executors.newFixedThreadPool(1000);

        Account account = new Account();

        UnSynAccount unSynAccount = new UnSynAccount();

        SynBlockAccount blockAccount = new SynBlockAccount();

        for(int i=0;i<500;i++){
            executorService.execute(account);
        }

        for(int i=0;i<500;i++){
            executorService.execute(blockAccount);
        }

        for(int i=0;i<500;i++){
            executorService.execute(unSynAccount);
        }

        executorService.shutdown();

        while (true){
            if(executorService.isTerminated()) {
                System.out.println("Account: "+account.toString());
                System.out.println("BlockAccount: "+blockAccount.toString());
                System.out.println("unSynAccount: "+unSynAccount.toString());
                break;
            }
        }

    }

}
